package com.kould.common.adapter;

import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;

import java.io.IOException;

public class SecretAdapter extends TypeAdapter<String> {
    private static final Gson gson = new Gson();

    /**
     * 序列化
     *
     * @param out   输出流
     * @param value 值
     * @throws IOException
     */
    @Override
    public void write(JsonWriter out, String value) throws IOException {
        out.value("");
    }

    /**
     * 反序列化
     *
     * @param in 输入流
     * @return
     * @throws IOException
     */
    @Override
    public String read(JsonReader in) throws IOException {
        String s = in.nextString();
        if (!"".equals(s)) {
            return s;
        } else {
            return null;
        }
    }
}
